<?php 
/*
**********************************************
JoomLeague TEAM PLAYERS MODULE
Copyright (c) 2007 JoomLeague.de
**********************************************
This program is free software; you can redistribute it and/or modify 
it under the terms of the GNU General Public License as published by 
the Free Software Foundation; either version 2 of the License, or 
(at your option) any later version.

This header must not be removed. Additional contributions/changes
may be added to this header as long as no information is deleted.
**********************************************

* TEAM PLAYERS MODULE
*
* 2007-08-05 - Version 0.91
*
* Displays the players from a choosen team, sorted by playerposition.
* There are some options for this module, which can be set in the 
* "Parameters" section of the module in Administration.
*

**********************************************
Get the latest version of JoomLeague at:
http://www.joomleague.de//
**********************************************
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
?>
<script type="text/javascript">
// <![CDATA[
function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = 'block';
	}
}
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
function JL_collapseAll(objs) {
var i;
for (i=0;i<objs.length;i++ ) {
objs[i].style.display = 'none';
}
}
// ]]>
</script>
<?
if (file_exists($mosConfig_absolute_path.'/components/com_joomleague/language/'.$mosConfig_lang.'.php')) {
  include_once($mosConfig_absolute_path.'/components/com_joomleague/language/'.$mosConfig_lang.'.php');
} 
else{
  include_once($mosConfig_absolute_path.'/components/com_joomleague/language/english.php');
}

require_once 'administrator/components/com_joomleague/joomleague.class.php';

$params = mosParseParams( $module->params );

$p = $params->project;
$show = $params->show; //default 0

$project = new JoomLeague( $database );
$project->load($p);

$team_id = $params->team;
if($team_id == 0) $team_id = $project->fav_team;
    
$team = new JL_Team( $database );
$team->load($team_id);


$query = sprintf("SELECT p.*, pt.id AS playertoolid, pt.*, pp.name as position 
                    FROM #__joomleague_players p, #__joomleague_playertool pt, #__joomleague_positions pp 
                   WHERE p.id = pt.player_id AND 
                         pt.project_id = %s AND 
                         team_id = %s AND 
                         pp.id = pt.position_id
                ORDER BY pp.ordering, pt.position_id
                 ", $project->id, $team_id);
$database->setQuery($query);

$rows = $database->loadObjectList();

?>

<?php if($show == 1){?><div align="center"><b><?php echo $project->name;?></b></div><?php };?>

<?php
  $k = 0;
  $poszaehl=0;
  $position = "";
  for ($i=0, $n=count( $rows ); $i < $n; $i++) {
    $row = &$rows[$i];
    if($position != $row->position){
      $position = $row->position;
      $poszaehl++;
      $k = 0;
?>

<? if ($poszaehl>1) echo "</table></div>    </td></tr></table>";?>
  <table width="100%">
    <tr class="sectiontableheader">
      <td align="center"><b><a href="javascript:switchMenu('m<?php echo $poszaehl;?>');" title="Spieler anzeigen"><?php echo $position;?></a></b></td>
    </tr>
		<tr>
			<td>
					<div id="m<?php echo $poszaehl;?>" style="display:block">
					<table cellpadding="4" cellspacing="0" border="0" width="100%">
<?php
    }
?>
    <tr class="<?php echo ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2'; ?>">
      <td align="center">
      <?php if($params->link_name == 0) {
      printf('%s %s',$row->firstname, $row->lastname);?></td>
      <?php };?>
      <?php if($params->link_name == 1) {
      echo '<a href="'.sefRelToAbs("index.php?option=com_joomleague&amp;func=showPlayer&amp;p=".$params->project."&amp;pid=".$row->playertoolid."&amp;Itemid=".$Itemid).'">'.$row->firstname.' '.$row->lastname.'</a>';?>

      </td>
      <?php };?>      
    </tr>
<?php
    $k = 1 - $k;
  } 
?>
<? if ($poszaehl>1) echo "</table></div>
</td></tr></table>";?>
<?
if ($params->collapsed == 1) { ?>
<script type="text/javascript">
// <![CDATA[
<?
for ($x=$poszaehl;$x>0;$x--)
{
	echo "document.getElementById('m".$x."').style.display='none';\n";
}
?>// ]]>
</script><? } ?>
